#include <iostream>
#include <cstring>
#include <sys/mman.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

#define SIZE 4096

using namespace std;

int main()
{
    int fd = open("lion.txt",O_RDWR|O_CREAT,0644);
    ftruncate(fd, SIZE);
    char* addr = (char*)mmap(NULL,SIZE,PROT_WRITE,MAP_SHARED,fd,0);

    const char* str = "hello world\n";
    memcpy(addr, str, strlen(str)+1);

    munmap(addr,SIZE);
    close(fd);

    int fd1 = open("lion.txt",O_RDWR|O_CREAT,0644);
    char buf[1024] = {0};
    read(fd1,buf,sizeof(buf));
    printf("%s",buf);
    close(fd1);

    return 0;
}